/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"605B652B-B77D-40A6-B56F-33D5EFA1CC44",variableType:8}
 */
var T_ganancias_percep = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"77A2B9A3-BD77-4304-9D6B-876B25694A22",variableType:8}
 */
var f_iva_1 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"16190295-B3C7-42D5-A6E1-4BE7D920FA74",variableType:8}
 */
var f_iva_2 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"4BBC39E4-E797-4214-A0AE-EB0AE8FE7531",variableType:8}
 */
var f_iva_3 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"699AD6CA-7AE4-464C-B344-AC68826037FB",variableType:8}
 */
var f_iva_4 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"BAB497F2-F47A-4473-B053-013F78AB52A6",variableType:8}
 */
var f_neto_1 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"07CE4988-8E10-467D-BD5D-68D152CCD04E",variableType:8}
 */
var f_neto_2 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"A240E1A7-28D5-4D37-B331-2D50B095419A",variableType:8}
 */
var f_neto_3 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"DFEF344E-7A0B-4C31-96ED-4996CCCE1FCD",variableType:8}
 */
var f_neto_4 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"2CA0F7D2-0E1C-4572-BE49-0FB5A65607D8",variableType:8}
 */
var iva_percep_1 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"21DA5C25-5A32-4E95-A8C7-48E1A06F33E6",variableType:8}
 */
var iva_percep_2 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"33D99396-6F52-4B94-99EF-9D64787656A1",variableType:8}
 */
var iva_percep_3 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"C9AC331C-75EE-4DBD-89D3-1BD41B73273C",variableType:8}
 */
var iva_percep_4 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"F15869A2-577E-4CDF-B9DB-D7F1A181D5DC",variableType:8}
 */
var porc_1 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"B18CC5DB-EBBE-449C-B190-58BD34EAC491",variableType:8}
 */
var porc_2 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"9DD56EF1-D910-44AA-951D-72BAF99F3E46",variableType:8}
 */
var porc_3 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"240027CE-3F1E-445B-84CD-7C0E0893CB88",variableType:8}
 */
var porc_4 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"1F539C88-B974-4CD5-A8B5-AA31BDF1766C",variableType:8}
 */
var T_ib_percep = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"9DCD2800-5F92-4D1A-9E28-B127E01E40BB",variableType:8}
 */
var T_importe = 0;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"C325F624-5DF2-41C5-827E-B885D45D3691",variableType:8}
 */
var T_itc = 0;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"D4BE1E93-7D3B-4DC5-93BA-7AED25BBBE80",variableType:8}
 */
var T_iva = 0;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"2669421D-19DE-4FED-A3C0-C5DF664576AE",variableType:8}
 */
var T_iva_percep = 0;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"4280056D-6AFE-4C8F-8B7D-A87A79A3F4ED",variableType:8}
 */
var T_neto = 0;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"E19D9EF7-E3BF-4E43-BE90-4EF8948EC82A",variableType:8}
 */
var T_neto_exento = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"00BA91A2-73E5-45F5-8BFC-AD2C5C59C012",variableType:8}
 */
var T_neto_monotrib = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"1D369F3F-F576-4111-92DF-A7CEF5E70BD3",variableType:8}
 */
var T_neto_no_grav = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"77AD5588-9A18-4D6F-9994-08A292777F3E",variableType:8}
 */
var T_neto_no_gravado = null;

/**
 *
 * @properties={typeid:24,uuid:"C408BB86-3D04-497D-ADCF-4A8F478BE4A6"}
 */
function calcular_totales()
{	
	globals.ghoja_desde_diario = 0;
	// armar dataset
	var tabla_totales = databaseManager.createEmptyDataSet(10,4)
	
	for ( var k = 0 ; k < 10 ; k ++ )
	{
		tabla_totales.setValue(k, 1, 0.00);
		tabla_totales.setValue(k, 2, 0.00);
		tabla_totales.setValue(k, 3, 0.00);
		tabla_totales.setValue(k, 4, 0.00);
	}
	
	// recorre foundset
	T_neto				= 0
	T_iva				= 0
	T_importe			= 0
	T_iva_percep		= 0
	T_itc				= 0
	T_neto_no_gravado	= 0
	T_ib_percep			= 0
	T_neto_monotrib		= 0 
	T_neto_exento		= 0 
	T_neto_no_grav		= 0
	T_ganancias_percep	= 0
	
	controller.sort("fecha_mov asc, cod_mov asc, letra asc, sucursal asc, nro_factura asc")
	
	for ( var i = 1 ; i <= controller.getMaxRecordIndex(); i++ )
	{
		controller.setSelectedIndex(i)
		neto_impresion 	= 0
		iva_impresion	= 0
		porc_impresion	= null
		if (neto != 0 && neto != null)
		{
			neto_impresion	= neto_signo
			iva_impresion	= iva_signo
			porc_impresion	= ctacte_pr_to_tasa_iva_porc.porc_impresion;
		}
		if (neto_2 != 0 && neto_2 != null)
		{
			neto_impresion	+= neto_2_signo
			iva_impresion	+= iva_2_signo
			if (ctacte_pr_to_tasa_iva_porc_2.porc_impresion != null && ctacte_pr_to_tasa_iva_porc_2.porc_impresion != ' ')
				porc_impresion = porc_impresion + '-' + ctacte_pr_to_tasa_iva_porc_2.porc_impresion;
		}
		if (neto_3 != 0 && neto_3 != null)
		{
			neto_impresion	+= neto_3_signo
			iva_impresion	+= iva_3_signo
			if (ctacte_pr_to_tasa_iva_porc_3.porc_impresion != null && ctacte_pr_to_tasa_iva_porc_3.porc_impresion != ' ')
				porc_impresion = porc_impresion + '-' + ctacte_pr_to_tasa_iva_porc_3.porc_impresion;
		}

		T_neto				+= neto_impresion
		T_iva				+= iva_impresion
		T_importe			+= importe_signo
		T_iva_percep		+= iva_percep_signo
		T_itc				+= itc_signo
		T_neto_no_gravado	+= neto_no_gravado_signo  
		T_ib_percep			+= ib_percep_signo
		T_ganancias_percep	+= ganancias_percep_signo

		if (ctacte_pr_to_proveedor.tipo_iva_id == globals.zconf_tipo_iva_monotributo)
			T_neto_monotrib += neto_no_gravado_signo
		else
		{
			if (ctacte_pr_to_proveedor.tipo_iva_id == globals.zconf_tipo_iva_exento)
				T_neto_exento += neto_no_gravado_signo
			else
				T_neto_no_grav += + neto_no_gravado_signo
		}
		if (neto != 0 && neto != null)
		{
			var k = ctacte_pr_to_tasa_iva_porc.tasa_iva_id;
				
			tabla_totales.setValue(k, 1, iva_porc)
			tabla_totales.setValue(k, 2, tabla_totales.getValue(k, 2) + iva_signo)
			tabla_totales.setValue(k, 3, tabla_totales.getValue(k, 3) + neto_signo)
		}
		
		if (neto_2 != 0 && neto_2 != null)
		{
			var k = ctacte_pr_to_tasa_iva_porc_2.tasa_iva_id;	
			tabla_totales.setValue(k, 1, iva_porc_2)			
			tabla_totales.setValue(k, 2, tabla_totales.getValue(k, 2) + iva_2_signo)
			tabla_totales.setValue(k, 3, tabla_totales.getValue(k, 3) + neto_2_signo)
		}
		if (neto_3 != 0 && neto_3 != null)
		{
			var k = ctacte_pr_to_tasa_iva_porc_3.tasa_iva_id;	
			tabla_totales.setValue(k, 1, iva_porc_3)			
			tabla_totales.setValue(k, 2, tabla_totales.getValue(k, 2) + iva_3_signo)
			tabla_totales.setValue(k, 3, tabla_totales.getValue(k, 3) + neto_3_signo)
		}
	} // fin del for 

	for ( var k = 1 ; k <= 10 ; k ++ )
	{
		if (tabla_totales.getValue(k, 1) != 0 && tabla_totales.getValue(k, 2) != 0 && tabla_totales.getValue(k, 3) != 0)		
		{   
			f_iva_1 	= tabla_totales.getValue(1, 2)
			f_iva_2 	= tabla_totales.getValue(2, 2)
			f_iva_3 	= tabla_totales.getValue(3, 2)
			f_iva_4 	= tabla_totales.getValue(4, 2)
			porc_1 		= tabla_totales.getValue(1, 1)
			porc_2 		= tabla_totales.getValue(2, 1)
			porc_3 		= tabla_totales.getValue(3, 1)
			porc_4 		= tabla_totales.getValue(4, 1)
			f_neto_1 	= tabla_totales.getValue(1, 3)
			f_neto_2 	= tabla_totales.getValue(2, 3)
			f_neto_3 	= tabla_totales.getValue(3, 3)
			f_neto_4 	= tabla_totales.getValue(4, 3)
		}
	}  
	
}

/**
 * @properties={typeid:24,uuid:"566EDEE6-C9F0-485F-BC5C-C1F646E7C6AF"}
 */
function imprimir() 
{
	//application.showFormInDialog(forms.diario_compras_2_imp,-1,-1,-1,-1,'diario compras',true,false,'dia_compra',true)
	forms.diario_compras_2_imp.controller.showPrintPreview(false);
}
